package rush.rushcampus.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import rush.rushcampus.common.Result;
import rush.rushcampus.dto.IdlePageDto;
import rush.rushcampus.dto.IdlePublishDto;
import rush.rushcampus.entity.Idle;
import rush.rushcampus.service.IIdleService;
import rush.rushcampus.vo.IdleInfoVo;
import rush.rushcampus.vo.IdleVo;

import java.util.List;

@RestController
@RequestMapping("/idle")
@Api(tags = "闲置模块")
public class IdleController {
    @Autowired
    private IIdleService idleService;
    @ApiOperation(value = "发布闲置信息")
    @PutMapping("/add")
    public Result addIdle(@RequestBody IdlePublishDto idlePublishDto){
        idleService.addIdle(idlePublishDto);
        return Result.success("发布成功");
    }
    @ApiOperation(value = "修改闲置信息")
    @PutMapping("/update")
    public Result updateIdle(@RequestBody IdlePublishDto idlePublishDto){
        Idle idle = new Idle();
        idleService.updateById(idle);
        return Result.success("修改成功");
    }
    @ApiOperation(value = "删除闲置信息")
    @PutMapping("/delete")
    public Result deleteIdle(Long id , Integer commentType){
        idleService.removeIdle(id , commentType);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "分页查询闲置信息")
    @PostMapping("/list")
    public Result list(@RequestBody IdlePageDto idlePageDto){
        List<IdleVo> IdleVoList = idleService.listIdleVo(idlePageDto);
        return Result.success(IdleVoList);
    }
    @ApiOperation(value = "根据id查询闲置信息")
    @GetMapping("/getIdleById")
    public Result getIdleById(Long id){
        IdleInfoVo idleInfoVo = idleService.getIdleById(id);
        Integer.valueOf(1);
        return Result.success(idleInfoVo);
    }

}
